 import Vue from 'vue'
 import VueRouter from 'vue-router'
 import Home from '../views/Home.vue'
 Vue.use(VueRouter)

 const routes = [{
     path: '/',
     name: 'Home',
     meta: {
       istrun: true
     },
     component: Home
   },
   {
     path: '/course',
     name: 'Course',
     meta: {
       istrun: true
     },
     // route level code-splitting
     // this generates a separate chunk (about.[hash].js) for this route
     // which is lazy-loaded when the route is visited.
     component: () => import( /* webpackChunkName: "about" */ '../views/Course.vue')
   },
   {
     path: '/discuss',
     name: 'Discuss',
     meta: {
       istrun: true
     },
     // route level code-splitting
     // this generates a separate chunk (about.[hash].js) for this route
     // which is lazy-loaded when the route is visited.
     component: () => import( /* webpackChunkName: "about" */ '../views/Discuss.vue')
   },
   {
     path: '/nav',
     name: 'Nav',
     meta: {
       istrun: true
     },
     // route level code-splitting
     // this generates a separate chunk (about.[hash].js) for this route
     // which is lazy-loaded when the route is visited.
     component: () => import( /* webpackChunkName: "about" */ '../views/Nav.vue')
   },
   {
     path: '/my',
     name: 'My',
     meta: {
       istrun: true
     },
     // route level code-splitting
     // this generates a separate chunk (about.[hash].js) for this route
     // which is lazy-loaded when the route is visited.
     component: () => import( /* webpackChunkName: "about" */ '../views/My.vue')
   },
   {
     path: '/course/1-1',
     name: '2',
     // route level code-splitting
     // this generates a separate chunk (about.[hash].js) for this route
     // which is lazy-loaded when the route is visited.
     component: () => import( /* webpackChunkName: "about" */ '../components/2.vue')
   },
   {
     path: '/login',
     name: 'Login',
     component: () => import('../components/Login.vue')
   }
 ]

 const router = new VueRouter({
   routes
 })

 export default router

 router.beforeEach((to, from, next) => {
   var isLogin = localStorage.getItem("isLogin")
   if(isLogin===null){
     isLogin="0"
   }
   console.log(isLogin)
   if (to.path == "/login" || to.path == "/register") {
     if (isLogin==="1") {
       next("/");
     } else {
       next();
     }
   } else {
     // requireAuth:可以在路由元信息指定哪些页面需要登录权限
     if (isLogin==="1") {
       next();
     } else {
       next("/login");
     }
   }
 })